<?php

declare(strict_types=1);

namespace Zlf\Unit;

/**
 * 运算计算
 * Class Compute
 * @package Zlf\Unit
 */
class Compute
{

    /**
     * 加法
     * @param int|string|float $num1
     * @param $num2
     * @param int|null $scale
     * @return float|int|string|null
     */
    public static function bcadd($num1, $num2, ?int $scale = 0)
    {
        $sum = bcadd((string)$num1, (string)$num2, $scale);
        return Number::format($sum);
    }


    /**
     * 减法
     * @param int|string|float $num1
     * @param $num2
     * @param int|null $scale
     * @return float|int|string|null
     */
    public static function bcsub($num1, $num2, int $scale = 0)
    {
        $sum = bcsub((string)$num1, (string)$num2, $scale);
        return Number::format($sum);
    }


    /**
     * 乘法
     * @param int|string|float $num1
     * @param $num2
     * @param int|null $scale
     * @return float|int|string|null
     */
    public static function bcmul($num1, $num2, int $scale = 0)
    {
        $sum = bcmul((string)$num1, (string)$num2, $scale);
        return Number::format($sum);
    }


    /**
     * 除法
     * @param int|string|float $num1
     * @param $num2
     * @param int|null $scale
     * @return float|int|string|null
     */
    public static function bcdiv($num1, $num2, int $scale = 0)
    {
        $sum = bcdiv((string)$num1, (string)$num2, $scale);
        return Number::format($sum);
    }
}